package org.jeecg.desen.error;


import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.error.service.IErrorRecordService;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public abstract class AbstractErrorService {

    @Autowired
    IErrorRecordService iErrorRecordService;

    protected void recordError(String title, int level, Exception e) {
        log.error(title, e);
        String errMsg = e.getMessage().length() > 400 ? e.getMessage().substring(0, 400) : e.getMessage();
        iErrorRecordService.recordSch(title, errMsg, level);
    }

    protected void recordError(String title, int level, String context) {
        log.error(title, context);
        iErrorRecordService.recordSch(title, context, level);
    }

    protected void recordError(String title, int level, String context, String memo) {
        log.error(title, context + memo);
        iErrorRecordService.recordSch(title, context, level, memo);
    }

    protected void recordError(String title, String context) {
        log.error(title);
        iErrorRecordService.recordSch(title, context, 1);
    }

    protected String recordError(String title) {
        log.error(title);
        iErrorRecordService.recordSch(title, "", 1);
        return title;
    }

    protected void recordError(String title, int level) {
        log.error(title);
        iErrorRecordService.recordSch(title, "", level);
    }
}
